import http from '../request';
const apibase = '/api/PackingPlan';
import qs from 'qs';
//获取订单信息
var GetOrders = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/GetOrders`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//获取灌包单
var GetPLists = function (data) {
  return new Promise ((resolve, reject) => {
    const datas = qs.stringify (data);
    http
      .post (apibase + `/GetWebPackingPlans?${datas}`)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//获取灌包单,分页
var GetWebPackingPagePlans = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/GetWebPackingPagePlans`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//获取灌装单生产记录明细
var GetPackingPlanRecordList = function (data) {
  return new Promise ((resolve, reject) => {
    const datas = qs.stringify (data);
    //PackingPlanID
    http
      .post (apibase + `/GetPackingPlanRecordList?${datas}`)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//获取订单明细
var GetOrderDetails = function (data) {
  return new Promise ((resolve, reject) => {
    const datas = qs.stringify (data);
    //OrderID
    http
      .post (apibase + `/GetOrderDetails?${datas}`)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//获取灌装单明细
var GetPackingPlanDetails = function (data) {
  return new Promise ((resolve, reject) => {
    const datas = qs.stringify (data);
    //PackingPlanID
    http
      .post (apibase + `/GetPackingPlanDetails?${datas}`)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//同步订单
var SynchroMoveOrder = function () {
  return new Promise ((resolve, reject) => {
    //UserID
    http
      .post (apibase + `/SynchroMoveOrder`)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//保存按钮
var SavePacking = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/SavePacking`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//下发
var SendPacking = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/SendPacking`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//反下发
var SendBackPacking = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/SendBackPacking`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//更改车间
var SegmentEditPacking = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/SegmentEditPacking`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//修改计划数量
var updPackingPlanByPlanQty = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/UpdPackingPlanByPlanQty`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//关闭/强制关闭灌装单
var ClosePacking = function (data, IsMsutClose = false) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/ClosePacking?IsMsutClose=${IsMsutClose}`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//ReStartPacking
var ReStartPacking = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/ReStartPacking`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//灌装单补料
var ReplenishmentPacking = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/ReplenishmentPacking`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//删除灌包物料
var DelPackingPlanDetail = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/DelPackingPlanDetail`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//设置基准
var SetIfBalance = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/SetIfBalance`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//修改明细
var SaveDetail = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/SaveDetail`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//查询工单绑定
var GetBindPackingPlanRelation = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/GetBindPackingPlanRelation`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//工单绑定
var BindPackingPlanRelation = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/BindPackingPlanRelation`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//工单解绑
var UnBindPackingPlanRelation = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/UnBindPackingPlanRelation`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
//预分配获取灌包单,分页
var GetWebPackingPagePlansByAllocate = function (data) {
  return new Promise ((resolve, reject) => {
    http
      .post (apibase + `/GetWebPackingPagePlansByAllocate`, data)
      .then (res => {
        resolve (res);
      })
      .catch (error => {
        reject (error);
      });
  });
};
export {
  GetOrders,
  GetPLists,
  GetWebPackingPagePlans,
  GetPackingPlanRecordList,
  GetOrderDetails,
  GetPackingPlanDetails,
  SynchroMoveOrder,
  SavePacking,
  SendPacking,
  SendBackPacking,
  SegmentEditPacking,
  ClosePacking,
  ReStartPacking,
  ReplenishmentPacking,
  DelPackingPlanDetail,
  SetIfBalance,
  GetBindPackingPlanRelation,
  BindPackingPlanRelation,
  UnBindPackingPlanRelation,
  updPackingPlanByPlanQty,
  SaveDetail,
  GetWebPackingPagePlansByAllocate,
};
